package web.jdbc.function;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import web.clazz.Clazz;
import web.jdbc.DataOperator;
/**用于删除Entity
 * @author 乐渊
 * @version 1.0
 * @see DataOperator
 * */
public class Delete<T> {

	private static PreparedStatement ps = null;
	private Connection conn = null;
	private T t;
	private Clazz clazz = null;
	
	public Delete(Connection conn, T t, Clazz clazz) {
		this.conn = conn;
		this.t = t;
		this.clazz = clazz;
	}

	public void getRS() throws SQLException {
		String sql ="DELETE FROM "+clazz.getName();
		new DataOperator<T>().collectData(t, clazz);
		if(DataOperator.keyColumn != null){
			sql+=" WHERE "+DataOperator.keyColumn+"=?";
			ps = conn.prepareStatement(sql);
			DataOperator.setData(ps, 1, DataOperator.keyValue);
			ps.execute();
			ps.close();
		}
	}

}
